﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace XNAVE3D
{
    class Nave
    {
        Vector3 position;
        public Model model;
        public  Matrix myWorld = Matrix.Identity;
        float divisor = 8.0f;

        public Nave(Vector3 position, Model model)
        {
            myWorld.Translation = position; 
            this.position = position;
            this.model = model;   
        }
        
        public void Update(GameTime gameTime)
        {
            Vector3 position = myWorld.Translation;
            if (Keyboard.GetState().IsKeyDown(Keys.D))
            {
                myWorld *= Matrix.CreateRotationY(MathHelper.ToRadians(-3));
            }
            if (Keyboard.GetState().IsKeyDown(Keys.A))
            {
                myWorld *= Matrix.CreateRotationY(MathHelper.ToRadians(3));
            }
            if (Keyboard.GetState().IsKeyDown(Keys.W) && divisor >= 0.5f)
            {
                divisor -= 0.05f;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.S) && divisor <= 13)
            {
                divisor += 0.05f;
            }
            myWorld.Translation = position;
            Vector3 rotation = -myWorld.Forward;
            myWorld *= Matrix.CreateTranslation(rotation / divisor);           
        }

        public void Draw(Matrix view, Matrix projection)
        {
            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (BasicEffect effectI in mesh.Effects)
                {
                    effectI.EnableDefaultLighting();
                    effectI.Projection = projection;
                    effectI.View = view;
                    effectI.World = myWorld;
                }
                mesh.Draw();
            }                        
        }
    }
}
